package com.fengyun.selfbfpp;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.beans.factory.support.RootBeanDefinition;

/**
 * 自定义BDRPP
 */
public class MyBeanDefinitionRegistryPostProcessor implements BeanDefinitionRegistryPostProcessor {

	/**
	 * @param registry the bean definition registry used by the application context
	 * @throws BeansException
	 */
	@Override
	public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
		System.out.println("invoke...postProcessBeanDefinitionRegistry");
		RootBeanDefinition rootBeanDefinition = new RootBeanDefinition(MyJavaBean.class);
		rootBeanDefinition.getPropertyValues()
				.add("id","1")
				.add("name","ahao");

		registry.registerBeanDefinition("myJavaBean", rootBeanDefinition);
	}

	/**
	 * @param beanFactory the bean factory used by the application context
	 * @throws BeansException
	 */
	@Override
	public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
		System.out.println("invoke...postProcessBeanFactory");
		BeanDefinition userBD = beanFactory.getBeanDefinition("user");
		userBD.getPropertyValues().add("name", "zt666");
	}
}
